package cn.renxuan.querys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.renxuan.entity.FS_DomesticWeather;
import cn.renxuan.enums.EWeatherDataSource;
import cn.renxuan.repository.DynamicParameters;

public class DomesticWeatherQuery extends BaseQuery<FS_DomesticWeather> {

    private String defaultTableAlias = "dw";

    private List<Long> idList;

    private Short year;

    private Byte month;

    private Byte day;

    private EWeatherDataSource datasource;

    private String citycode;

    private String countycode;

    public List<Long> getIdList() {
        return idList;
    }

    public void setIdList(List<Long> idList) {
        this.idList = idList;
    }

    public void setYear(Short year) {
        this.year = year;
    }

    public void setMonth(Byte month) {
        this.month = month;
    }

    public void setDay(Byte day) {
        this.day = day;
    }

    public void setDatasource(EWeatherDataSource dataSource) {
        this.datasource = dataSource;
    }

    public void setCitycode(String citycode) {
        this.citycode = citycode;
    }

    public void setCountycode(String countycode) {
        this.countycode = countycode;
    }

    @Override
    public Map<String, DynamicParameters> getQuerySql() {
        Map<String, DynamicParameters> querySqls = new HashMap<String, DynamicParameters>();
        StringBuilder sbsql = new StringBuilder();
        DynamicParameters parameters = new DynamicParameters();

        if (!isContainDeleted) {
            sbsql.append(String.format(" AND %s.isdeleted = 0 ", defaultTableAlias));
        }

        if (idList != null && idList.size() > 0) {
            sbsql.append(String.format(" and %s.id in (%s) ", defaultTableAlias,
                    getCollectionSymbol(idList, parameters, "idList")));
            // parameters.add("IdList", idList);
        }

        // 城市代码过滤
        if (citycode != null && !citycode.isEmpty()) {
            sbsql.append(String.format(" and %s.citycode = ? ", defaultTableAlias));
            parameters.add("citycode", citycode);
        }

        // 县代码过滤
        if (countycode != null && !countycode.isEmpty()) {
            sbsql.append(String.format(" and %s.countycode = ? ", defaultTableAlias));
            parameters.add("countycode", countycode);
        }

        // 年份过滤
        if (year != null) {
            sbsql.append(String.format(" and %s.year = ? ", defaultTableAlias));
            parameters.add("year", year);
        }

        // 月份过滤
        if (month != null) {
            sbsql.append(String.format(" and %s.month = ? ", defaultTableAlias));
            parameters.add("month", month);
        }

        // 日期过滤
        if (day != null) {
            sbsql.append(String.format(" and %s.day = ? ", defaultTableAlias));
            parameters.add("day", day);
        }

        // 数据源过滤
        if (datasource != null) {
            sbsql.append(String.format(" and %s.datasource = ? ", defaultTableAlias));
            parameters.add("datasource", datasource);
        }

        querySqls.put(sbsql.toString(), parameters);
        return querySqls;
    }
}
